package com.kkd.kkdapp.activity;

import com.kkd.kkdapp.R;
import com.kkd.kkdapp.base.BaseActivity;
import com.kkd.kkdapp.utils.PreferenceUtils;
import com.kkd.kkdapp.utils.SystemUtils;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

/***
 * 
 * @name 账户安全
 * 
 * @author mty
 * 
 * @date 2016-12-27 12:10
 * 
 */
public class AccountSecurityActivity extends BaseActivity implements
		OnClickListener {

	private RelativeLayout top_img; // 返回键
	private RelativeLayout realname_rl; // 实名认证
	private ImageView icon_img3; // 实名认证三角图标
	private TextView noname_tv; // 未实名认证
	private TextView name_tv; // 实名认证-》姓名
	private TextView ap_tv; // 账户手机号
	private RelativeLayout update_password; // 修改密码
	private TextView sinauid_tv; // 新浪UID

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_account_security);
		initView();
		setListener();
	}

	/****
	 * 初始化控件
	 */
	public void initView() {
		top_img = (RelativeLayout) findViewById(R.id.top_img);
		realname_rl = (RelativeLayout) this.findViewById(R.id.realname_rl);
		noname_tv = (TextView) this.findViewById(R.id.noname_tv);
		name_tv = (TextView) this.findViewById(R.id.name_tv);
		icon_img3 = (ImageView) this.findViewById(R.id.icon_img3);
		ap_tv = (TextView) this.findViewById(R.id.ap_tv);
		update_password = (RelativeLayout) this
				.findViewById(R.id.update_password);
		sinauid_tv = (TextView) this.findViewById(R.id.sinauid_tv);
	}

	/****
	 * 注册监听事件
	 */
	public void setListener() {
		top_img.setOnClickListener(this);
		realname_rl.setOnClickListener(this);
		update_password.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		Intent intent;
		switch (v.getId()) {
		case R.id.top_img: // 返回键
			finish();
			break;
		case R.id.realname_rl: // 实名认证
			SystemUtils.onEvent("Account_Sett_FeedBack", 1);
			intent = new Intent(this, ForTenderActivity.class);
			startActivity(intent);
			break;
		case R.id.update_password: // 修改密码
			intent = new Intent(this, ModifyPassWordActivity.class);
			startActivity(intent);
			break;
		}

	}

	@Override
	protected void onResume() {
		super.onResume();
		// 用户真实姓名
		String idCardAndrealName = PreferenceUtils.getInstance()
				.getIdCardAndRealName(this);
		if (TextUtils.isEmpty(idCardAndrealName)) {
			icon_img3.setVisibility(View.VISIBLE);
			realname_rl.setClickable(true);
			noname_tv.setText("未实名");
			name_tv.setVisibility(View.GONE);
			noname_tv.setVisibility(View.VISIBLE);
		} else {
			icon_img3.setVisibility(View.GONE);
			realname_rl.setClickable(false);
			String[] idCardAndrealNamelist = idCardAndrealName.split("&");
			name_tv.setVisibility(View.VISIBLE);
			noname_tv.setVisibility(View.GONE);
			name_tv.setText(idCardAndrealNamelist[1]);
		}

		// 账户手机号
		String phone = PreferenceUtils.getInstance().getPhone(this);
		if (!TextUtils.isEmpty(phone)) {
			String firstThreePhone = phone.substring(0, 3);
			String afterFourPhone = phone.substring(7, 11);
			ap_tv.setText(firstThreePhone + "****" + afterFourPhone);
		}

		// 新浪UID
		if (!TextUtils.isEmpty(PreferenceUtils.getInstance().getSinaUid(this))) {
			sinauid_tv.setText(PreferenceUtils.getInstance().getSinaUid(this));
		}
	}

}
